﻿/*--------------------------------------------------------------------\
|       _____ _                      __  __ _    _  _____ _    _      |
|      / ____| |                    |  \/  | |  | |/ ____| |  | |     |
|     | (___ | |__   __ _ _ __ _ __ | \  / | |  | | (___ | |__| |     |
|      \___ \| '_ \ / _` | '__| '_ \| |\/| | |  | |\___ \|  __  |     |
|      ____) | | | | (_| | |  | |_) | |  | | |__| |____) | |  | |     |
|     |_____/|_| |_|\__,_|_|  | .__/|_|  |_|\____/|_____/|_|  |_|     |
|                             | |                                     |
|                             |_| Copyright(C) Shawn Sagady 2010      |
|=-------------------------------------------------------------------=|
|   Please reference the CREDITS.TXT file for license and credits.    |
\--------------------------------------------------------------------*/


using System;
using System.Collections;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace SharpMUSH
{
    public static class Server
    {
        const int backlog = 20;
        static bool running = false;

        private static Socket server;

        public static void Start(int port)
        {
            Console.WriteLine("SERVER: Starting on port {0}", port);

            server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            server.Bind(new IPEndPoint(IPAddress.Any, port));
            server.Listen(backlog);
            running = true;

            Console.WriteLine("SERVER: Listening For Connections.");
            while (running)
            {
                Socket conn = server.Accept();
                new Connection(conn);
            }
        }
    }
}
